//
//  TestViewController.m
//  BabyNow
//
//  Created by fox on 14-4-9.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import "TestViewController.h"
#import "BN_DynamicHelper.h"

@interface TestViewController ()
{
    
    __weak IBOutlet UIButton *startUploadBtn_;
    
    BN_DynamicHelper *dynamicHelper_;
    
    __weak IBOutlet UILabel *percentLbl_;
    __weak IBOutlet UIProgressView *processView_;
    
    CGRect percentLblOriRect_;
}

@end

@implementation TestViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    dynamicHelper_ = [[BN_DynamicHelper alloc]init];
    percentLblOriRect_ = percentLbl_.frame;
    percentLbl_.text = @"0%";
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)startUpload:(id)sender {
    /*
    percentLbl_.frame = percentLblOriRect_;
    percentLbl_.text = @"0%";
    processView_.progress = 0;
    startUploadBtn_.enabled = NO;
    NSString *content = @"测试只发布图片";
    NSArray *imgArray = @[@"1.png",@"2.png",@"3.png",@"4.png",@"5.png",@"6.png",@"7.png",@"8.png",@"9.png"];
    NSString *fileName1 = @"1.png";
    NSString *imgPath1 = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"png"];
    NSString *mimeType = [IMB_FileHelper mimeType:imgPath1];
    NSLog(@"image1 -> mimeType:%@",mimeType);
    
    NSString *fileName2 = @"2.png";
    NSString *imgPath2 = [[NSBundle mainBundle]pathForResource:@"2" ofType:@"png"];
    mimeType = [IMB_FileHelper mimeType:imgPath2];
    NSLog(@"image2 -> mimeType:%@",mimeType);
    
    NSString *fileName3 = @"3.png";
    NSString *imgPath3 = [[NSBundle mainBundle]pathForResource:@"3" ofType:@"png"];
    mimeType = [IMB_FileHelper mimeType:imgPath3];
    
    NSString *fileName4 = @"4.png";
    NSString *imgPath4 = [[NSBundle mainBundle]pathForResource:@"4" ofType:@"png"];
    mimeType = [IMB_FileHelper mimeType:imgPath4];
    
    NSString *fileName5 = @"5.png";
    NSString *imgPath5 = [[NSBundle mainBundle]pathForResource:@"5" ofType:@"png"];
    mimeType = [IMB_FileHelper mimeType:imgPath5];
    
    NSString *fileName6 = @"5.png";
    NSString *imgPath6 = [[NSBundle mainBundle]pathForResource:@"6" ofType:@"png"];
    mimeType = [IMB_FileHelper mimeType:imgPath6];
    
    NSString *fileName7 = @"7.png";
    NSString *imgPath7 = [[NSBundle mainBundle]pathForResource:@"7" ofType:@"png"];
    mimeType = [IMB_FileHelper mimeType:imgPath7];
    
    NSString *fileName8 = @"8.png";
    NSString *imgPath8 = [[NSBundle mainBundle]pathForResource:@"8" ofType:@"png"];
    mimeType = [IMB_FileHelper mimeType:imgPath8];
    
    NSString *fileName9 = @"9.png";
    NSString *imgPath9 = [[NSBundle mainBundle]pathForResource:@"9" ofType:@"png"];
    mimeType = [IMB_FileHelper mimeType:imgPath9];
    
    NSData *imgData1 = [NSData dataWithContentsOfFile:imgPath1];
    NSData *imgData2 = [NSData dataWithContentsOfFile:imgPath2];
    NSData *imgData3 = [NSData dataWithContentsOfFile:imgPath3];
    NSData *imgData4 = [NSData dataWithContentsOfFile:imgPath4];
    NSData *imgData5 = [NSData dataWithContentsOfFile:imgPath5];
    NSData *imgData6 = [NSData dataWithContentsOfFile:imgPath6];
    NSData *imgData7 = [NSData dataWithContentsOfFile:imgPath7];
    NSData *imgData8 = [NSData dataWithContentsOfFile:imgPath8];
    NSData *imgData9 = [NSData dataWithContentsOfFile:imgPath9];
    
    //NSDictionary *fileImageDict = @{fileName1:imgData1,fileName2:imgData2,fileName3:imgData3,fileName4:imgData4,fileName5:imgData5,fileName6:imgData6,fileName7:imgData7,fileName8:imgData8,fileName9:imgData9};
    NSDictionary *fileImageDict = @{@"250":imgData1,@"520":imgData2,fileName3:imgData3};
    
    //[dynamicHelper_ addObserver:processView_ forKeyPath:@"fileUploadProgress" options:NSKeyValueObservingOptionNew context:NULL];
    
    // 注意：将来根据上传的是图片还是视频，mimeType可以直接取预定义的常量
    // 图片：FILE_MIME_TYPE_FOR_PNG   视频：FILE_MIME_TYPE_FOR_MP4
    
    
    __block float lastProgress = 0;
    [dynamicHelper_ postDynamicWithSubj:content postType:ENUM_DYNAIMC_FOR_CLASS fileMimeType:mimeType filesInfoDict:fileImageDict completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            NSLog(@"%@",errMsg);
        }else{
            NSLog(@"测试发布动态内容结果：%@",result);
        }
        startUploadBtn_.enabled = YES;
    } uploadProcessingHandler:^(double progress) {
        
        int percent = (int)round(progress * 100);
        NSLog(@"%d",percent);
        percentLbl_.text = [NSString stringWithFormat:@"%d%%",percent];
        CGRect frame = percentLbl_.frame;
        frame.origin.x += processView_.bounds.size.width * (progress - lastProgress);
        percentLbl_.frame = frame;
        NSLog(@"标签的位置：%f",percentLbl_.frame.origin.x);
        processView_.progress = progress;
        lastProgress = progress;
    }];
    */
}

- (IBAction)test:(id)sender {
    NSLog(@"Test");
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
